/**
 * Created by baiguiren on 1/23/17.
 */


let async = require('async');

async.waterfall([
  function (callback) {
    callback(null, 'one', 'two');
  },
  function (arg1, arg2, callback) {
    // arg1 now equals 'one' and arg2 now equals to 'two'
    console.log(arg1, arg2);
    callback(null, 'three');
  },
  function (arg1, callback) {
    // arg1 now equals to 'three'
    console.log(arg1);
    callback(null, 'done');
  }
], function (err, result) {
  // result now equals 'done'
  console.log(result);
});

// Or, with named functions:
async.waterfall([
  myFirstFunction,
  mySecondFunction,
  myThirdFunction,
], function (err, result) {
  // result now equals 'done'
  console.log(result);
});

function myFirstFunction(callback) {
  callback(null, 'one', 'two');
}

function mySecondFunction(arg1, arg2, callback) {
  // arg1 now equals 'one' and arg2 now equals 'two'
  console.log(arg1, arg2);
  callback(null, 'three');
}

function myThirdFunction(arg1, callback) {
  // arg1 now equals to 'three'
  console.log(arg1);
  callback(null, 'done');
}